import { axios } from '@/utils/request'
import Vue from 'vue'
// import storage from 'store'
// import { ACCESS_TOKEN } from '@/store/mutation-types'

import { ACCESS_TOKEN } from '@/store/mutation-types'

// const userApi = {
//   Login: '/auth/login',
//   Logout: '/auth/logout',
//   ForgePassword: '/auth/forge-password',
//   Register: '/auth/register',
//   twoStepCode: '/auth/2step-code',
//   SendSms: '/account/sms',
//   SendSmsErr: '/account/sms_err',
//   // get my info
//   UserInfo: '/user/info',
//   UserMenu: '/user/nav'
// }

const userApi = {
  Login: '/security/user/login',
  Logout: '/security/user/logout',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSms: '/account/sms',
  SendSmsErr: '/account/sms_err',
  // get my info
  UserInfo: '/security/user/getInfo',
  UserMenu: '/security/user/getMenu'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  return axios({
    url: userApi.Login,
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha (parameter) {
  return axios({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getInfo () {
  const token = Vue.ls.get(ACCESS_TOKEN)
  // const token = storage.get(ACCESS_TOKEN)
  // const tokenObj2 = { 'token': token }
  // console.info('token==>', token)
  return axios({
    url: userApi.UserInfo,
    // params: tokenObj2,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'token': token
    }
  })
}

export function getCurrentUserNav (token) {
  const token2 = Vue.ls.get(ACCESS_TOKEN)
  return axios({
    url: userApi.UserMenu,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'token': token2
    }
  })
}

export function logout () {
  const token = Vue.ls.get(ACCESS_TOKEN)
  return axios({
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'token': token
    }
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return axios({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}
